# 创建一个字典  
freq = {'a': 1, 'b': 2, 'c': 3}  

for i in freq:
    print(f"Key: {i}, Value: {freq[i]}")
 
items_iterator = iter(freq.items())  
try:  
    while True:  
        # 调用迭代器的__next__()方法，Python中通过next()函数实现  
        key, value = next(items_iterator)  
        print(key, value)  
except StopIteration:  
    # 当迭代器没有更多元素时，next()会抛出StopIteration异常  
    # 捕获此异常以优雅地结束循环  
    print("迭代完成")



# 使用.items()方法  
items_view = freq.items()  
# 遍历items_view  
for key, value in items_view:  
    print(f"Key: {key}, Value: {value}")  
  
# 输出将会是：  
# Key: a, Value: 1  
# Key: b, Value: 2  
# Key: c, Value: 3